#include<iostream>
using namespace std;
const int N = 100;
typedef pair<int, int> PII;
int map[N][N];
int st[N][N];
int n, m;
PII q[N * N];
int dx[4] = { 0,-1,0,1 };
int dy[4] = { -1,0,1,0 };
int bfs(int x, int y)
{
	int area = 0;
	int hh = 0;
	int tt = 0;
	q[0] = { x,y };
	st[x][y] = 1;
	while (hh <= tt) {
		PII temp = q[hh++];
		area++;
		for (int i = 0; i < 4; i++) {
			if (map[temp.first][temp.second] >> i & 1)continue;
			int a = dx[i] + temp.first;
			int b = dy[i] + temp.second;
			if (st[a][b])continue;
			if (a < 0 || a >= n || b < 0 || b >= m)continue;
			q[++tt] = { a,b };
			st[a][b] = 1;
		}
	}
	return area;
}
int main()
{
	cin >> n >> m;
	int ans = 0;
	int ma = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cin >> map[i][j];
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (!st[i][j]) {
				int area = bfs(i, j);
				ans++;
				ma = max(ma, area);
			}
		}
	}
	cout << ans << endl;
	cout << ma << endl;
	return 0;
}